﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

namespace Cemit.NetFramework.Demo.Tutorial1
{
    /// <summary>
    /// 本教程会进行获取Ping演示，并在text上显示Ping或连接失败
    /// </summary>
    [System.Obsolete("该DEMO已过时")]
    public sealed class NetworkManager : MonoBehaviour
    {
        public Text text;

        void Start()
        {
            //设置监听
            PolyNetwork.OnConnectionFailed += (t) => text.text = $"连接失败：{t}";

            //连接至服务器
            PolyNetwork.Connect("127.0.0.1", 2333);
        }

        private void Update()
        {
            //判断服务器是否已经连接
            if (PolyNetwork.IsConnected)
            {
                text.text = "Ping: " + PolyNetwork.Ping.ToString();
            }
        }
    }
}